package com.bosc.automationui.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class StringToDateUtil {

    private static final String pattern = "yyyyMMdd";

    public static java.sql.Date strToDate(String strDate) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        java.util.Date d = null;
        try {
            d = format.parse(strDate);
        } catch (Exception e) {
            e.printStackTrace();
        }

        java.sql.Date date = null;
        try {
            date = new java.sql.Date(d != null ? d.getTime() :format.parse("19700101").getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static void main(String[] main) throws ParseException{
        System.out.println(strToDate("20190101").toString());
    }
}
